package controller

import (
	"mumu_stock_trad/model"
	"mumu_stock_trad/util"
	"net/http"

	"github.com/gin-gonic/gin"
	log "github.com/sirupsen/logrus"
)

// 从接口获取数据
func UpdateCategory(c *gin.Context) {
	data, err := util.GetCategory()
	if err != nil {
		log.Info("Error fetching stock data: ", err.Error())
		// 返回JSON响应
		c.JSON(http.StatusOK, NewResponse(Fail, gin.H{
			"list": data,
		}))
		return
	}

	model.SaveCategory(data)

	// 返回JSON响应
	c.JSON(http.StatusOK, NewResponse(Success, gin.H{
		"list": data,
	}))
}
